<?php

  $user = $_REQUEST["user"];
  $dbname =  $_REQUEST["dbname"];
  $password =  $_REQUEST["password"];
  $query = $_REQUEST["query"]? stripslashes($_REQUEST["query"]):"";


if (is_array($vars)) {
  foreach ($vars as $param => $value) {
    switch ($param) {
      case "user": $user =  trim($value,"\"");
            //echo "user -> ".$value;
      break;
      case "query": $query =  stripslashes(trim($value,"\""));
            //echo "query -> ".$value;
      break;
      case "dbname": $dbname =  trim($value,"\"");
            //echo "dbname -> ".$value;
      break;
      case "password": $password =  trim($value,"\"");
            //echo "password -> ".$value;
      break;
    }
  }
}

if(!$user || !$password || !$dbname || !$query) {
?>
<form action="<?php echo $PHP_SELF?>" method="GET">
User: <input type="text" name="user" value="<?echo $user?>"><br>
Password: <input type="password" name="password"><br>
Database: <input type="text" name="dbname" value="<?echo $dbname?>"><br>
Query: <textarea cols="40" rows="8" name="query"><?echo $query?>
</textarea>
<input type="hidden" name="wakka" value="<?echo $_REQUEST[wakka]?>">
<input type="submit" value="Execute">
</form>

<?php } else {
  if( substr($query,0,7) != "select ") {
    $query = "select 'You are a bad person! Trying to modify the database. Use select like everyone else please' \"Error Message\" from dual";
  }

  // logon
  $conn = ora_logon($user."@".$dbname, $password);

  // execute query
  printf("%s<br />",$query);
  ora_print_query($query,$conn);
} ?>
<?

function ora_print_query($query,$conn) {

  $curs = ora_open($conn);

  ora_commitoff($conn);

  // execute query
  ora_parse($curs, $query);
  ora_exec($curs);

  $ncols = ora_numcols($curs);

  // print out results

  if($ncols > 0 ) {
    ?><table border="1"><tr><?
    for ($i=0; $i<$ncols; $i++) {
     printf("<th>%s</th>",
       ora_columnname($curs, $i));
    }
?></tr><?
    while (ora_fetch($curs)) {
      printf("<tr>");
        for ($i=0; $i<$ncols; $i++) {
        $col = ora_getcolumn($curs, $i);
        printf("<td>%s</td>", $col?$col:"&nbsp;");
      }
      printf("</tr>");
    }
  } //cols > 0
  ora_close($curs);
 ?>
</table>
<?php } ?>